home *** CD-ROM | disk | FTP | other *** search
/ Digitalfoto 118 / Digitalfoto 118.iso / mac / programas / 00 / start.swf / scripts / FFPSControllerSymbol.as next >
Text File  |  2009-11-16  |  5KB  |  201 lines

  1. FPSController = function()
  2. {
  3.    this.setFPSTarget(this._targetInstanceName);
  4.    this.initPause();
  5.    this.init();
  6.    this.initProps();
  7. };
  8. FPSController.prototype.init = function()
  9. {
  10.    this.sT = getTimer();
  11.    this.tF = this._tget._totalframes;
  12.    this.isStop = false;
  13.    if(this.playMode == "Forward")
  14.    {
  15.       this._tget.gotoAndStop(1);
  16.    }
  17.    else if(this.playMode == "Reverse")
  18.    {
  19.       this._tget.gotoAndStop(this.tF);
  20.    }
  21.    else if(this.playMode == "PingPong")
  22.    {
  23.       this.initPingPong();
  24.    }
  25.    else if(this.playMode == "Random")
  26.    {
  27.       this.FgotoToRandom();
  28.    }
  29. };
  30. FPSController.prototype.initPingPong = function()
  31. {
  32.    this.initialDirection = this.initialDirection != undefined ? this.initialDirection : "Forward";
  33.    this.playDirection = this.initialDirection.substring(0,1).toLowerCase();
  34.    if(this.playDirection == "f")
  35.    {
  36.       this._tget.gotoAndStop(1);
  37.    }
  38.    else if(this.playDirection == "r")
  39.    {
  40.       this._tget.gotoAndStop(this.tF);
  41.    }
  42.    else
  43.    {
  44.       this.tget.gotoAndStop(1);
  45.       this.playDirection = "f";
  46.    }
  47. };
  48. FPSController.prototype.setFPSTarget = function(tget)
  49. {
  50.    if(typeof tget == "string")
  51.    {
  52.       this._tget = this._parent[tget];
  53.    }
  54.    else if(typeof tget == "movieclip")
  55.    {
  56.       this._tget = tget;
  57.    }
  58.    this.tF = this._tget._totalframes;
  59.    this.attachMethods();
  60. };
  61. FPSController.prototype.getFPSTarget = function()
  62. {
  63.    return this._tget;
  64. };
  65. FPSController.prototype.setFPS = function(fps)
  66. {
  67.    this.fps = fps;
  68.    this.initPause();
  69. };
  70. FPSController.prototype.getFPS = function()
  71. {
  72.    return this.fps;
  73. };
  74. FPSController.prototype.initPause = function()
  75. {
  76.    this.pauseFor = Math.floor(1000 / this.fps);
  77. };
  78. FPSController.prototype.setPlayMode = function(playMode, initialDirection)
  79. {
  80.    this.playMode = playMode;
  81.    this.initialDirection = initialDirection;
  82.    if(playMode == "PingPong")
  83.    {
  84.       this.initPingPong();
  85.    }
  86. };
  87. FPSController.prototype.getPlayMode = function()
  88. {
  89.    return this.playMode;
  90. };
  91. FPSController.prototype.FgotoAndStop = function(fnum)
  92. {
  93.    this.gotoAndStop(fnum);
  94.    this._tget.isStop = true;
  95. };
  96. FPSController.prototype.FgotoAndPlay = function(fnum)
  97. {
  98.    this.gotoAndStop(fnum);
  99.    this._tget.isStop = false;
  100. };
  101. FPSController.prototype.Fstop = function()
  102. {
  103.    this.stop();
  104.    this._tget.isStop = true;
  105. };
  106. FPSController.prototype.Fplay = function()
  107. {
  108.    this._tget.isStop = false;
  109. };
  110. FPSController.prototype.FnextFrame = function()
  111. {
  112.    if(this._tget.cF == this._tget.tF && this._tget.playMode == "Forward")
  113.    {
  114.       this.gotoAndStop(1);
  115.    }
  116.    else if(this._tget.cF == this._tget.tF && this._tget.playMode == "PingPong")
  117.    {
  118.       this.prevFrame();
  119.       this._tget.playDirection = "r";
  120.    }
  121.    else
  122.    {
  123.       this.nextFrame();
  124.    }
  125. };
  126. FPSController.prototype.FprevFrame = function()
  127. {
  128.    if(this._tget.cF == 1 && this._tget.playMode == "Reverse")
  129.    {
  130.       this.gotoAndStop(this._tget.tF);
  131.    }
  132.    else if(this._tget.cF == 1 && this._tget.playMode == "PingPong")
  133.    {
  134.       this.nextFrame();
  135.       this._tget.playDirection = "f";
  136.    }
  137.    else
  138.    {
  139.       this.prevFrame();
  140.    }
  141. };
  142. FPSController.prototype.FgotoToRandom = function()
  143. {
  144.    var _loc2_ = 1 + Math.floor(Math.random() * (this._tget.tF - 1));
  145.    this.gotoAndStop(_loc2_);
  146. };
  147. FPSController.prototype.onEnterFrame = function()
  148. {
  149.    if(!this.isStop)
  150.    {
  151.       this.tS = getTimer() - this.sT;
  152.       this.cF = this._tget._currentframe;
  153.       if(this.tS >= this.pauseFor)
  154.       {
  155.          if(this.playMode == "Forward")
  156.          {
  157.             this._tget.FnextFrame();
  158.          }
  159.          else if(this.playMode == "Reverse")
  160.          {
  161.             this._tget.FprevFrame();
  162.          }
  163.          else if(this.playMode == "PingPong")
  164.          {
  165.             if(this.playDirection == "f")
  166.             {
  167.                this._tget.FnextFrame();
  168.             }
  169.             else if(this.playDirection == "r")
  170.             {
  171.                this._tget.FprevFrame();
  172.             }
  173.          }
  174.          else if(this.playMode == "Random")
  175.          {
  176.             this._tget.FgotoToRandom();
  177.          }
  178.          this.sT = getTimer();
  179.       }
  180.    }
  181. };
  182. FPSController.prototype.attachMethods = function()
  183. {
  184.    this._tget._tget = this;
  185.    this._tget.FgotoAndStop = this.FgotoAndStop;
  186.    this._tget.FgotoAndPlay = this.FgotoAndPlay;
  187.    this._tget.Fstop = this.Fstop;
  188.    this._tget.Fplay = this.Fplay;
  189.    this._tget.FnextFrame = this.FnextFrame;
  190.    this._tget.FprevFrame = this.FprevFrame;
  191.    this._tget.FgotoToRandom = this.FgotoToRandom;
  192.    ASSetPropFlags(this._tget,["_tget","FgotoAndStop","FgotoAndPlay","Fstop","Fplay","FnextFrame","FprevFrame","FgotoToRandom"],1);
  193. };
  194. FPSController.prototype.initProps = function()
  195. {
  196.    this.addProperty("fps",this.getFPS,this.setFPS);
  197.    this.addProperty("_tget",this.getFPSTarget,this.setFPSTarget);
  198.    this.addProperty("playMode",this.getPlayMode,this.setPlayMode);
  199. };
  200. Object.registerClass("FFPSControllerSymbol",FPSController);
  201.